home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Control del ratón / MouseConnect / MouseConnect.cs next >
Encoding:
Text File  |  2002-04-18  |  1.8 KB  |  60 lines

  1. // ------------------------------------------
  2. // MouseConnect.cs ⌐ 2001 by Charles Petzold
  3. // ------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class MouseConnect: Form
  9. {
  10.      const int iMaxPoints = 1000;
  11.      int       iNumPoints = 0;
  12.      Point[]   apoint     = new Point[iMaxPoints];
  13.  
  14.      public static void Main()
  15.      {
  16.           Application.Run(new MouseConnect());
  17.      }
  18.      public MouseConnect()
  19.      {
  20.           Text = "Manejo del rat≤n: Pulse, arrastre rßpido y suelte";
  21.           BackColor = SystemColors.Window;
  22.           ForeColor = SystemColors.WindowText;
  23.           ClientSize += ClientSize;     // Doblar el ßrea cliente.
  24.      }
  25.      protected override void OnMouseDown(MouseEventArgs mea)
  26.      {
  27.           if (mea.Button == MouseButtons.Left)
  28.           {
  29.                iNumPoints = 0;
  30.                Invalidate();
  31.           }
  32.      }
  33.      protected override void OnMouseMove(MouseEventArgs mea)
  34.      {
  35.           if (mea.Button == MouseButtons.Left)
  36.           {
  37.                apoint[iNumPoints++] = new Point(mea.X, mea.Y);
  38.  
  39.                Graphics grfx = CreateGraphics();
  40.                grfx.DrawLine(new Pen(ForeColor), mea.X, mea.Y, 
  41.                                                  mea.X, mea.Y + 1);
  42.               grfx.Dispose();
  43.           }
  44.      }
  45.      protected override void OnMouseUp(MouseEventArgs mea)
  46.      {
  47.           if (mea.Button == MouseButtons.Left)
  48.                Invalidate();
  49.      }
  50.      protected override void OnPaint(PaintEventArgs pea)
  51.      {
  52.           Graphics grfx = pea.Graphics;
  53.           Pen      pen  = new Pen(ForeColor);
  54.  
  55.           for (int i = 0   ; i < iNumPoints - 1; i++)
  56.                for (int j = i + 1; j < iNumPoints; j++)
  57.                     grfx.DrawLine(pen, apoint[i], apoint[j]);
  58.     }
  59. }
  60.